/**
 * 
 */
package com.thor.palmmall.rest.elecharges;

import org.springframework.beans.factory.annotation.Autowired;

import com.thor.palmmall.api.pay.alipay.AlipayService;
import com.thor.palmmall.api.pay.union.UnionPayService;
import com.thor.palmmall.api.pay.wechat.WeChatService;
import com.thor.palmmall.api.pay.wechat.WxPayOrderNotifyResponse;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class APaymentCallBackServiceImpl implements APaymentCallBackService {
  @Autowired
  private AlipayService alipayService;
  @Autowired
  private WeChatService weChatService;

  @Autowired
  private UnionPayService unionPayService;

  @Override
  public String alipayCallBack(String request) {
    boolean isSuccess = alipayService.callBack(request);
    if (isSuccess) {
      return "success";
    } else {
      return "通知失败";
    }
  }

  @Override
  public String weChatCallBack(String request) {
    boolean isSuccess = weChatService.verifyNotify(request);
    if (isSuccess) {
      return WxPayOrderNotifyResponse.success("SUCCESS");

    } else {
      return WxPayOrderNotifyResponse.success("Failure");
    }
  }

  public String unionPayCallBack(String resp) {
    boolean isSuccess = unionPayService.callBack(resp);
    if (isSuccess) {
      return "ok";
    } else {
      return "通知失败";
    }
  }
}
